import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { TitleItem } from "../common/item/TitleItem";
import { ObjTeamCreate } from "../common/ObjTeamCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { TilePanel } from "../equipment/TilePanel";
import { WrestleTopCellRenderer } from "./cellRendener/WrestleTopCellRenderer";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { WrestlePageData } from "./wrestleData/WrestlePageData";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SWrestleToplists } from "../../../../Message/Public/SWrestleToplists";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { GButton } from "../../../../com/mui/controls/GButton";
import { _onlyMyServer } from "../../../../this/_onlyMyServer";
type int = number;
//class WrestleTopListPanel
    
    export  class WrestleTopListPanel /* flash.display.Sprite */
    {
        constructor(arg1: int, arg2: Boolean)
        {
            
            this._orderType = arg1;
            this._onlyMyServer = arg2;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createSpBannerAndBg(0, 0, 802, 450, "", this);
            var loc1=Language.getString(42320);
            if (!this._onlyMyServer) 
            {
                loc1 = Language.getString(42321);
            }
            var loc2=new Vector.<TitleItem>();
            loc2.push(new TitleItem(Language.getString(42322), 70));
            loc2.push(new TitleItem(Language.getString(42323), 180));
            loc2.push(new TitleItem(Language.getString(42324), 70));
            loc2.push(new TitleItem(Language.getString(42325), 60));
            loc2.push(new TitleItem(Language.getString(42326), 80));
            loc2.push(new TitleItem(Language.getString(42327), 80));
            loc2.push(new TitleItem(Language.getString(42328), 70));
            loc2.push(new TitleItem(Language.getString(42329), 90));
            loc2.push(new TitleItem(loc1, 100));
            var loc3=ObjTeamCreate.createTitles(loc2);
            ObjCreate.setObjAttri(loc3, 2, 8, -1, -1, this);
            this._tfNoResult = ObjCreate.createTextField(Language.getString(44251), 390, 210, 200, 20, this, GlobalStyle.textFormat6);
            this._tfNoResult.visible = false;
            this._topListPanel = new TilePanel();
            this._topListPanel.setSize(802, 420);
            this._topListPanel.rowHeight = 42;
            this._topListPanel.columnWidth = 802;
            this._topListPanel.setStyle("cellRenderer", WrestleTopCellRenderer);
            this._topListPanel.x = 5;
            this._topListPanel.y = 30;
            this.addChild(this._topListPanel);
            this._pageSelecter = new PageSelecter();
            this._pageSelecter.mode = PageSelecter.InputMode;
            this._pageSelecter.x = 207;
            this._pageSelecter.y = 458;
            this._pageSelecter.pageTextBoxSize = 50;
            this.addChild(this._pageSelecter);
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.onChange);
            this._btnRefresh = ObjCreate.createGButton(Language.getString(42213), 610, 457, 54, 22, this);
            this._btnRefresh.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnRefreshClick);
            this._btnMyPos = ObjCreate.createGButton(Language.getString(42352), 730, 457, 70, 22, this, "LinkButton");
            this._btnMyPos.addEventListener(flash.events.MouseEvent.CLICK, this.onClickMyPos);
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }

        /* internal  */onClickMyPos(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.getList(true);
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            this.getList();
            return;
        }

        /* internal  */onBtnRefreshClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.getList();
            return;
        }

        /* internal  */onChange(arg1: Object /* flash.events.Event */): void
        {
            this.getList();
            return;
        }

        /* internal  */getList(arg1: Boolean=false): void
        {
            this._isRequestData = true;
            var loc1=new WrestlePageData();
            loc1.pageNum = this._pageSelecter.currentPage;
            loc1.pageSize = this.pageSize;
            loc1.onlyMyServer = this._onlyMyServer;
            loc1.orderObjType = this._orderType;
            loc1.isShowMyPos = arg1;
            Dispatcher.dispatchEvent(new DataEvent(EventName.WrestleGetTopList, loc1));
            return;
        }

        public updateTopList(arg1: SWrestleToplists): void
        {
            if (arg1.orderObjType == this._orderType && arg1.onlyMyServer == this._onlyMyServer && this._isRequestData) 
            {
                this._topList = arg1;
                this._pageSelecter.maxPage = arg1.pageNum;
                this._pageSelecter.currentPage = arg1.page;
                this.updateList();
                this.updateVisible();
                this._isRequestData = false;
            }
            return;
        }

        /* internal  */updateList(): void
        {
            var loc1=[];
            var loc2=0;
            while (loc2 < this._topList.toplists.length) 
            {
                loc1.push({"onlyMyServer": _onlyMyServer, "list": this._topList.toplists[loc2]});
                ++loc2;
            }
            this._topListPanel.dataProvider = new DataProvider(loc1);
            this._topListPanel.drawNow();
            return;
        }

        /* internal  */updateVisible(): void
        {
            var loc1=this._topList && this._topList.toplists.length > 0;
            this._topListPanel.visible = loc1;
            this._tfNoResult.visible = !loc1;
            return;
        }

        public get orderType(): int
        {
            return this._orderType;
        }

        public get isOnlyMyServer(): Boolean
        {
            return this._onlyMyServer;
        }

        /* internal */ /* const */pageSize: int=10;

        /* internal */ /* var */_orderType: int;

        /* internal */ /* var */_onlyMyServer: Boolean;

        /* internal */ /* var */_tfNoResult: Object /* flash.text.TextField */;

        /* internal */ /* var */_topListPanel: TilePanel;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_btnRefresh: GButton;

        /* internal */ /* var */_btnMyPos: GButton;

        /* internal */ /* var */_isRequestData: Boolean=false;

        /* internal */ /* var */_topList: SWrestleToplists;
    }
